from sklearn.tree import DecisionTreeRegressor
from sklearn import datasets
from sklearn.tree import export_graphviz
import graphviz
# from sklearn.datasets import fetch_california_housing

boston = datasets.load_boston()
X = boston.data
y = boston.target

DTR = DecisionTreeRegressor(max_depth = 3)
DTR.fit(X, y)
print(DTR.score(X, y))

export_graphviz(DTR, out_file = 'regress_tree.dot',
               feature_names = boston.feature_names)
with open('regress_tree.dot') as f:
    dot_graph = f.read()
print(dot_graph)
graph = graphviz.Source(dot_graph)
graph.render('regress_tree')